<?php
/**
 * The News Model does the back-end heavy lifting for the News Controller
 */
class Allservices_Model
{
	/**
	 * Holds instance of database connection
	 */
	private $db;
		
	public function __construct()
	{
		$this->db = new MysqlImproved_Driver;
	}
	
	/**
	 * Fetches article based on supplied name
	 * 
	 * @param string $author
	 * 
	 * @return array $article
	 */
	public function get_article()
	{		
		//connect to database
		$this->db->connect();
		$this->get_page_data();
		$article['page_title'] = $this->page_data['title'];
		$article['page_description'] = $this->page_data['description'];
		$article['page_keywords'] = $this->page_data['keywords'];
		$article['content'] = $this->get_all_services();
		
		
		return $article;
	}
	
	public function get_all_services(){
		$this->db->prepare(
				"
				SELECT
				`service_title`,
				`service_link`,
				`service_description`,
				`service_image`
				FROM
				`services`
				ORDER
				BY
				`id`
				DESC;
				"
		);
		$this->db->query();
	
		$all_services_content = "";
		while($all_services_data = $this->db->fetch('array')){
			
			$all_services_content .= "
			
				<!-- Begin Service Item -->
				<div class=\"service-item\">
					<div class=\"service-img-wrap\">
						<a class=\"lightbox\" href=\"../images/services/".$all_services_data['service_image']."\"><img class=\"service-img\" src=\"/images/services/".$all_services_data['service_image']."\" alt=\"".$all_services_data['service_title']."\" /></a>
					</div>
					<h3 class=\"service-h left\">".$all_services_data['service_title']."</h3>
					<div class=\"details-butt right\">
						<p>
							<a href=\"/services/".$all_services_data['service_link'].".html\">Details</a>
							<img src=\"/views/images/goto-arr.png\" alt=\"Service Details\" />
						</p>
					</div>
					<div class=\"service-parag clear\">
						".$all_services_data['service_description']."
					</div>
				</div>
				<!-- End Service Item -->
			
			";
			
		}
		return $all_services_content;
	}
	public function get_page_data(){
		//prepare query
		$this->db->prepare
		(
				"
				SELECT
				`page`,
				`title`,
				`description`,
				`keywords`
				FROM
				`page_description`
				WHERE
				`page` = 'services'
				LIMIT
				1
				;
				"
		);
	
		//execute query
		$this->db->query();
	
		$this->page_data = $this->db->fetch('array');
		return $this->page_data;
	}
	
	
	
}